﻿var columns =
            [
                { display: 'Key', name: 'WagesBillID', type: 'text', hide: 1 },
                 { display: 'BillState', name: 'BillState', type: 'text', hide: 1 },
                { display: '单号', name: 'WagesBillNO', mintWidth: 80, width: 120 },
                { display: '工作组', name: 'WorkGroupName', mintWidth: 80, width: 120 },
                { display: '单据状态', name: 'BillStateName', mintWidth: 60, width:60 },
                { display: '开始日期', name: 'StartDate', mintWidth: 140, width: 140 },
                { display: '结束日期', name: 'EndDate', mintWidth: 140, width: 140 },
                { display: '总计件工资（元）', name: 'PieceWages1', mintWidth: 80, width: 140 },
                { display: '总扣废品费（元）', name: 'SumScrapMoney', mintWidth: 80, width: 140 },
                { display: '总组长提成（元）', name: 'HeadmanAward', mintWidth: 80, width: 120 },
                { display: '总生活费（元）', name: 'LiftMoney1', mintWidth: 80, width: 120 },
                { display: '总扣其他费（元）', name: 'OtherMoney1', mintWidth: 80, width: 120 },
                { display: '总补贴药费（元）', name: 'SumSubsidyMoney', mintWidth: 80, width: 120 },
                { display: '总实发工资（元）', name: 'wages1', mintWidth: 80, width: 120 },
              // { display: '单子状态', name: 'BillStateName', mintWidth: 80, width: 120 },
                { display: '添加时间', name: 'CreateTime', mintWidth: 160, width: 160 }

//                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
//                { display: '批次号', name: 'WagesBillNO', mintWidth: 80, width: 120 },
//                { display: '工作组', name: 'RefeName', mintWidth: 80, width: 120 },
//                { display: '开始日期', name: 'StartDate', mintWidth: 80, width: 120 },
//                { display: '结束日期', name: 'EndDate', mintWidth: 80, width: 120 },
//                { display: '计件工资', name: 'PieceWages', mintWidth: 80, width: 140 },
//                { display: '扣废品费', name: 'ScrapMoney', mintWidth: 80, width: 140 },
//                { display: '组长提成', name: 'HeadmanAward', mintWidth: 80, width: 120 },
//                { display: '生活费', name: 'LiftMoney', mintWidth: 80, width: 120 },
//                { display: '扣其他费', name: 'OtherMoney', mintWidth: 80, width: 120 },
//                { display: '补贴药费', name: 'SubsidyMoney', mintWidth: 80, width: 120 },
//                { display: '实发工资', name: 'Wages', mintWidth: 80, width: 120 },
//                { display: '单子状态', name: 'BillStateName', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    initligerGrid();
    initDataControls();
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
});

function initligerGrid() {
    manager = null;
    manager = $("#WagesGrid").ligerGrid({
        columns: columns,
        title: '工作组列表',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
//                                    { line: true },
            //                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' }
                    {line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        parms: { isNoInit: "1", billNo: $("#billNo").val(), groupName: $("#groupName").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val() },
        url: "../Wages/GetJsonOfWages?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.WagesBillID); }
    });
}

//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["WagesBillID"].toString();
    dialogView(billId);
}
function dialogView(billId) {
    $.ligerDialog.open({ url: "../Wages/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: '../Wages/Add', height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
//function deleteOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
//    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
//        if (yes) {
//            $.get("../Wages/Delete?id=" + row["Id"].toString(), {}, function (data) {
//                if (data != undefined && data == "9") {
//                    initligerGrid();
//                }
//            });
//        }
//    });
//}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    if (row["BillState"].toString() == "1") { $.ligerDialog.success('已提交，不能修改!'); return; }
    $.ligerDialog.open({ url: '../Wages/Add?id=' + row["WagesBillID"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
  
}


//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}